using com.haopintui.entity;
using System;
using System.Collections;
using System.Text;
using util;
namespace com.haopintui.util
{
	public class UserUtil
	{
		public static ArrayList query_cms_list(CmsForm cmsForm)
		{
			HttpService httpService = cmsForm.httpService;
			long user_id = cmsForm.appBean.user_id;
			string user_key = cmsForm.appBean.user_key;
			string user_name = cmsForm.appBean.user_name;
			string cms_url = Constants.cms_url;
			string text = httpService.post_http(cms_url, string.Concat(new object[]
			{
				"user_id=",
				user_id,
				"&user_name=",
				user_name,
				"&user_key=",
				user_key,
				"&user_token="
			}), null);
			new UnicodeEncoding();
			ArrayList arrayList = new ArrayList();
			int num = text.IndexOf("items");
			while ((num = text.IndexOf("\"app_id\"", num)) != -1)
			{
				UserCms userCms = new UserCms();
				userCms.app_id = StringUtil.subString(text, num, "\"app_id\":\"", "\"");
				userCms.user_id = StringUtil.subString(text, num, "\"user_id\":\"", "\"");
				string text2 = StringUtil.subString(text, num, "\"title\":\"", "\"");
				text2 = UnicodeUtil.Unicode2String(text2);
				userCms.title = text2;
				arrayList.Add(userCms);
				num++;
			}
			return arrayList;
		}
		public static ArrayList query_taoke_item_list(CmsForm cmsForm)
		{
			HttpService httpService = cmsForm.httpService;
			long user_id = cmsForm.appBean.user_id;
			string cms_app_id = cmsForm.appBean.cms_app_id;
			string user_key = cmsForm.appBean.user_key;
			string arg_36_0 = cmsForm.appBean.user_name;
			string user_taoke_url = Constants.user_taoke_url;
			string text = httpService.post_http(user_taoke_url, string.Concat(new object[]
			{
				"user_id=",
				user_id,
				"&app_id=",
				cms_app_id,
				"&user_key=",
				user_key,
				"&user_token="
			}), null);
			ArrayList arrayList = new ArrayList();
			int num = text.IndexOf("items");
			while ((num = text.IndexOf("\"num_iid\"", num)) != -1)
			{
				TaokeItem taokeItem = new TaokeItem();
				taokeItem.num_iid = StringUtil.subString(text, num, "\"num_iid\":\"", "\"");
				taokeItem.user_id = StringUtil.subString(text, num, "\"user_id\":\"", "\"");
				taokeItem.app_id = StringUtil.subString(text, num, "\"app_id\":\"", "\"");
				taokeItem.activity_id = StringUtil.subString(text, num, "\"activity_id\":\"", "\"");
				string text2 = StringUtil.subString(text, num, "\"title\":\"", "\"");
				text2 = UnicodeUtil.Unicode2String(text2);
				taokeItem.title = text2;
				taokeItem.tkRate = double.Parse(StringUtil.subString(text, num, "\"common_commission_rate\":\"", "\""));
				taokeItem.taoke_status = int.Parse(StringUtil.subString(text, num, "\"taoke_status\":", ","));
				string text3 = StringUtil.subString(text, num, "\"taoke_status_err\":\"", "\"");
				text3 = UnicodeUtil.Unicode2String(text3);
				taokeItem.taoke_status_err = text3;
				arrayList.Add(taokeItem);
				num++;
			}
			return arrayList;
		}
		public static bool submit_taoke_item(CmsForm cmsForm, AlimamaClick alimamaClick)
		{
			HttpService httpService = cmsForm.httpService;
			long user_id = cmsForm.appBean.user_id;
			string cms_app_id = cmsForm.appBean.cms_app_id;
			string user_key = cmsForm.appBean.user_key;
			string arg_36_0 = cmsForm.appBean.user_name;
			string user_taoke_create_url = Constants.user_taoke_create_url;
			string postDataStr = string.Concat(new string[]
			{
				"user_id=" + user_id,
				"&user_key=" + user_key,
				"&user_token=",
				"&app_id=" + cms_app_id,
				"&num_iid=" + alimamaClick.num_iid,
				"&url=" + alimamaClick.url,
				"&coupon_url=" + alimamaClick.coupon_url,
				"&short_url=" + alimamaClick.short_url,
				"&tao_token=" + alimamaClick.tao_token,
				"&coupon_link_tao_token=" + alimamaClick.coupon_link_tao_token
			});
			httpService.post_http(user_taoke_create_url, postDataStr, null);
			return true;
		}
		public static GoodsItem query_goods(CmsForm cmsForm, string num_iid, out string out_log)
		{
			GoodsItem result;
			try
			{
				HttpService httpService = cmsForm.httpService;
				long user_id = cmsForm.appBean.user_id;
				string user_key = cmsForm.appBean.user_key;
				string arg_2A_0 = cmsForm.appBean.user_name;
				string user_goods_url = Constants.user_goods_url;
				string text = httpService.post_http(user_goods_url, string.Concat(new object[]
				{
					"user_id=",
					user_id,
					"&num_iid=",
					num_iid,
					"&user_key=",
					user_key,
					"&user_token="
				}), null);
				if (text.Contains("\"num_iid\":"))
				{
					GoodsItem goodsItem = new GoodsItem();
					string text2 = StringUtil.subString(text, 0, "\"title\":\"", "\"");
					text2 = UnicodeUtil.Unicode2String(text2);
					goodsItem.title = text2;
					goodsItem.num_iid = num_iid;
					out_log = "";
					result = goodsItem;
				}
				else
				{
					out_log = text;
					result = null;
				}
			}
			catch (Exception ex)
			{
				out_log = "出错啦！！！" + ex.ToString();
				result = null;
			}
			return result;
		}
		public static UserCmsTongji query_user_cms_tongji(CmsForm cmsForm, out string out_log)
		{
			UserCmsTongji result;
			try
			{
				HttpService httpService = cmsForm.httpService;
				long user_id = cmsForm.appBean.user_id;
				string cms_app_id = cmsForm.appBean.cms_app_id;
				string user_key = cmsForm.appBean.user_key;
				string arg_36_0 = cmsForm.appBean.user_name;
				string cms_tongji_url = Constants.cms_tongji_url;
				string text = httpService.post_http(cms_tongji_url, string.Concat(new object[]
				{
					"user_id=",
					user_id,
					"&app_id=",
					cms_app_id,
					"&user_key=",
					user_key,
					"&user_token="
				}), null);
				if (text.Contains("\"all\":"))
				{
					UserCmsTongji userCmsTongji = new UserCmsTongji();
					userCmsTongji.all = int.Parse(StringUtil.subString(text, 0, "\"all\":\"", "\","));
					userCmsTongji.have = int.Parse(StringUtil.subString(text, 0, "\"have\":\"", "\""));
					out_log = "";
					result = userCmsTongji;
				}
				else
				{
					out_log = text;
					result = null;
				}
			}
			catch (Exception ex)
			{
				out_log = "出错啦！！！" + ex.ToString();
				result = null;
			}
			return result;
		}
	}
}
